
package com.hlkj.pay.controller.openapi.callback;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.Map;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.app.ad.IAdOrderCallBackService;
import com.hlkj.pay.app.ad.constant.AdConstant;
import com.hlkj.pay.controller.BaseController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2024/09/12 11:32
 */
@Tag(name = "广告订单支付第三方回调")
@RestController
@RequiredArgsConstructor
@Slf4j
public class AdPayOrderCallBackController extends BaseController {

    private final IAdOrderCallBackService adOrderCallBackService;

    @Operation(summary = "订单状态回调")
    @PostMapping(value = AdConstant.AD_TRANS_ASYNC_CALLBACK_URL + "{adId}", produces = "text/plain")
    String orderStatusCallBack(@PathVariable("adId") Long adId, @RequestParam Map<String, Object> params) {
        // 从请求体中读取数据
        log.info("pay call back data:{}", JsonUtils.toJsonString(params));
        // 解析请求体中的数据
        return adOrderCallBackService.orderStatusCallBack(adId, JsonUtils.toJsonPrettyString(params));
    }

    @Operation(summary = "退款状态回调")
    @PostMapping(value = AdConstant.AD_REFUND_ASYNC_CALLBACK_URL + "{adId}", produces = "text/plain")
    String refundCallBack(@PathVariable("adId") Long adId, @RequestParam Map<String, Object> params) {
        // 从请求体中读取数据
        log.info("refund call back data:{}", JsonUtils.toJsonString(params));
        return adOrderCallBackService.refundCallBack(adId, JsonUtils.toJsonPrettyString(params));
    }

    @Operation(summary = "充值状态回调")
    @PostMapping(value = AdConstant.AD_RECHARGE_ASYNC_CALLBACK_URL + "{adId}", produces = "text/plain")
    String rechargeCallBack(@PathVariable("adId") Long adId, @RequestParam Map<String, Object> params) {
        // 从请求体中读取数据
        log.info("recharge call back data:{}", JsonUtils.toJsonString(params));
        return adOrderCallBackService.rechargeCallBack(adId, params);
    }

}
